home *** CD-ROM | disk | FTP | other *** search
- /*
- * Listing 2: main() routine and test code for get_str().
- * Includes the OS-dependent routines sys_getchar()
- * and sys_putchar().
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <bios.h>
- #include <string.h>
-
- #define INBUFSIZ 70
- char inbuf[INBUFSIZ + 1];
-
- void get_str( char *str, int len );
-
- void main( void )
- {
-
- while (1)
- {
- printf("\ntype 'quit' to quit.\nprompt> ");
- get_str(inbuf, INBUFSIZ);
-
- if (stricmp(inbuf, "quit") == 0)
- break;
-
- printf(" Got: \"%s\"\n", inbuf);
- }
- }
-
-
- /*********************************************************
- * The following two routines will need to be changed,
- * in order to use get_str() in a different environment.
- *********************************************************/
-
- /*
- * Put a character to the output device.
- * Expand \n to \r\n.
- */
- void sys_putchar( char ch )
- {
-
- putchar(ch);
- if (ch == '\n')
- putchar('\r');
- }
-
-
- /*
- * Get a character from the input device.
- * Use the BIOS call so we can detect arrow keys.
- */
- int sys_getchar( void )
- {
- int ch;
-
- ch = bioskey(0); /* wait and get a key */
-
- if ((ch & 0xff) != 0) /* if not an extended key, */
- ch &= 0xff; /* use only the ASCII part */
- return (ch);
- }
-